package com.example.sh.shrio.Controller;

import com.example.sh.shrio.modle.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

public class TsContro {

    @RequestMapping("/index")
    public String index()
    {

        return "/index";
    }

    @RequestMapping("/login")
    public String login()
    {

        return "/login";
    }


    @RequestMapping("/hdlogin")
    public String hdlogin(@RequestParam("username" ) String uname, @RequestParam("passwd") String passwd, @RequestParam("session") HttpSession session)
    {
       try {

           UsernamePasswordToken token = new UsernamePasswordToken(uname, passwd);
           Subject us = SecurityUtils.getSubject();
           us.login(token);
           User user = (User) us.getPrincipal();
           session.setAttribute("user", user);
           return "/index";

       }catch (Exception e)
       {
           return "/hdlogin";
       }


    }




}
